﻿package export
{
	import com.dusk.tool.DataBase;
	
	import flash.utils.Dictionary;
	
	public class FlowerSoul
	{
		
		private const allTypeSoul:Vector.<String> = new <String>["atk", "crit", "def", "emp", "hit", "hp", "miss"];
		public const MAX_SOUL_LEVEL:int = 5;
		
		public function FlowerSoul():void
		{
			this.soulLevel = new DataBase();
			this.allCurEffect = new Dictionary();
			for each(var item:String in allTypeSoul)
			{
				if (soulLevel != null)
				{
					soulLevel[item] = 0;
				}
			}
		}
		
		private var soulLevel:DataBase;
		private var allCurEffect:Dictionary;
		
		public function setSoulLevelByType(param1:String, param2:int):void
		{
			if (soulLevel == null)
			{
				throw("soulLevel 为空！");
			}
			soulLevel[param1] = param2;
		}//设置花魂等级
		
		public function getSoulLevelByType(param1:String):int
		{
			if (soulLevel == null)
			{
				throw("soulLevel 为空！");
			}
			return soulLevel[param1] == undefined ? 0 : soulLevel[param1];
		}//获取花魂等级
		
		public function refreshAllCurEffect():void
		{
			if (this.allCurEffect == null)
			{
				throw("allCurEffect 为空！");
			}
			this.allCurEffect = new Dictionary();
			for each(var item:String in this.allTypeSoul)
			{
				this["getProp_" + item]();
			}
		}
		
		public function upgradeSoulLevelByType(param1:String):String
		{
			if (this.getSoulLevelByType(param1) < this.MAX_SOUL_LEVEL)
			{
				this.setSoulLevelByType(param1, this.getSoulLevelByType(param1) + 1);
				this.refreshAllCurEffect();
				return "升级成功";
			}
			else
			{
				this.refreshAllCurEffect();
				return "已达最高等级";
			}
		}
		
		public function getUpDataByType(param1:String):Object
		{
			var _loc1_:Object = {};
			_loc1_.type = param1;
			_loc1_.curLevel = this.getSoulLevelByType(param1);
			_loc1_.needNum = _loc1_.curLevel >= this.MAX_SOUL_LEVEL ? 0 : Math.pow(2, _loc1_.curLevel) * 10;
			_loc1_.curEffect = this["getProp_" + param1]();
			return _loc1_;
		}//升级页面获取信息
		
		
		//获取，设置存档信息
		public function getSaveObj():String
		{
			var _loc1_:Array = [];
			for each (var item:String in this.allTypeSoul)
			{
				_loc1_.push(item + "~" + this.getSoulLevelByType(item));
			}
			return _loc1_.join("|");
		}
		
		public function setSaveObj(param1:String):void
		{
			var _loc1_:Array = param1.split("|");
			var _loc2_:Array;
			for each(var item:String in _loc1_)
			{
				_loc2_ = item.split("~");
				this.setSoulLevelByType(_loc2_[0], _loc2_[1]);
			}
			this.refreshAllCurEffect();
		}//获取，设置存档信息
		
		public function getProp_atk():Object
		{
			if (allCurEffect == null)
			{
				throw("allCurEffect 为空！");
			}
			if (allCurEffect.atk != undefined)
			{
				return allCurEffect.atk;
			}
			else
			{
				var atkObj:Object = {};
				var lv:int = this.getSoulLevelByType("atk");
				atkObj.type = "atk";
				atkObj.odds = 0.02 * lv;
				atkObj.duration = lv;
				allCurEffect.atk = atkObj;
			}
			return atkObj;
		}//攻击时有odds点概率增加破甲buff，持续duration秒
		
		public function getProp_crit():Object
		{
			if (allCurEffect == null)
			{
				throw("allCurEffect 为空！");
			}
			if (allCurEffect.crit != undefined)
			{
				return allCurEffect.crit;
			}
			else
			{
				var critObj:Object = {};
				var lv:int = this.getSoulLevelByType("crit");
				critObj.type = "crit";
				critObj.treshold = 100 - 8 * lv;
				critObj.rate = 0.125;
				allCurEffect.crit = critObj;
			}
			return critObj;
		}//暴击值高于treshold，按照rate增加伤害
		
		public function getProp_def():Object
		{
			if (allCurEffect == null)
			{
				throw("allCurEffect 为空！");
			}
			if (allCurEffect.def != undefined)
			{
				return allCurEffect.def;
			}
			else
			{
				var defObj:Object = {};
				var lv:int = this.getSoulLevelByType("def");
				defObj.type = "def";
				defObj.key = 1 - 0.02 * lv;
				allCurEffect.def = defObj;
			}
			return defObj;
		}//baseHero 的reduceHp中引用，所受伤害*=key
		
		public function getProp_emp():Object
		{
			if (allCurEffect == null)
			{
				throw("allCurEffect 为空！");
			}
			if (allCurEffect.emp != undefined)
			{
				return allCurEffect.emp;
			}
			else
			{
				var empObj:Object = {};
				var lv:int = this.getSoulLevelByType("emp");
				empObj.type = "emp";
				empObj.treshold = 0.15 * lv;
				empObj.rate = 1 + 0.2 * lv;
				allCurEffect.emp = empObj;
			}
			return empObj;
		}//魔法百分比低于treshold时，回蓝*rate
		
		public function getProp_hit():Object
		{
			if (allCurEffect == null)
			{
				throw("allCurEffect 为空！");
			}
			if (allCurEffect.hit != undefined)
			{
				return allCurEffect.hit;
			}
			else
			{
				var hitObj:Object = {};
				var lv:int = this.getSoulLevelByType("hit");
				hitObj.type = "hit";
				hitObj.key = 2 * lv;
				allCurEffect.hit = hitObj;
			}
			return hitObj;
		}//命中值，在roleproperties引用，增加key点被动
		
		public function getProp_hp():Object
		{
			if (allCurEffect == null)
			{
				throw("allCurEffect 为空！");
			}
			if (allCurEffect.hp != undefined)
			{
				return allCurEffect.hp;
			}
			else
			{
				var hpObj:Object = {};
				var lv:int = this.getSoulLevelByType("hp");
				hpObj.type = "hp";
				hpObj.treshold = 0.05 * lv;
				hpObj.rate = 0.25;
				allCurEffect.hp = hpObj;
			}
			return hpObj;
		}//生命值降低a%，攻击加成rate * a%，最高treshold
		
		public function getProp_miss():Object
		{
			if (allCurEffect == null)
			{
				throw("allCurEffect 为空！");
			}
			if (allCurEffect.miss != undefined)
			{
				return allCurEffect.miss;
			}
			else
			{
				var missObj:Object = {};
				var lv:int = this.getSoulLevelByType("miss");
				missObj.type = "miss";
				missObj.odds = 0.15 * lv;
				missObj.rate = 2 * lv;
				allCurEffect.miss = missObj;
			}
			return missObj;
		}//闪避时有odds点概率对怪物造成伤害，倍率为rate
	}
}